<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/maintain/new_plan.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/autoComplete.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/project_device_alert.css">
</script>
<style scoped>
    .footer button{
      border: 0;
    }
  </style>
<!-- <title>提现记录</title> -->
<div class="layui-containner leon-style">
    <form class="layui-form" action="" lay-filter="formData">
        <div class="layui-fluid">
            <div class="layui-title">新增保养计划信息</div>
            <ul class="box layui-row">
                <li class="layui-col-md3 layui-col-sm3">
                    <div class="layui-input-block">
                        <span class="inner">
                            保养计划编号
                        </span>
                        <span class="layui-input-box"></span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>保养计划名称:
                        </span>
                        <span class="layui-input-box">
                            <input type="text" lay-verify="required" required name="tcPlanName" class="layui-input">
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner" style="padding-left: 8px;">
                            保养计划状态:
                        </span>
                        <span class="layui-input-box">
                            <div class="layui-input-block">
                                <input type="radio" name="tcPlanStatus" value="0" title="启用" class="layui-radio" checked="">
                                <input type="radio" name="tcPlanStatus" value="1" title="停用" class="layui-radio">
                            </div>
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>保养负责人:
                        </span>
                        <div class="layui-input-box completeWrap">
                            <input name="tcPlanGen01" id="gen02" value="" autocomplete="off" class="layui-input"
                                required lay-verify="required" />
                        </div>
                    </div>
                </li>
                <li class="layui-col-md3 layui-col-sm3">
                    <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>计划开始时间:
                        </span>
                        <span class="layui-input-box">
                            <input type="text" name="tcPlanStart" required lay-verify="required" id="startTime"
                                placeholder="" autocomplete="off" class="layui-input ">
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner" style="padding-left: 8px;">
                            计划结束时间:
                        </span>
                        <span class="layui-input-box">
                            <input type="text" name="tcPlanEnd" id="endTime" placeholder="" autocomplete="off"
                                class="layui-input ">
                        </span>
                    </div>
                  <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>计划频率:
                        </span>
                        <span class="layui-input-box">
                            <select name="tcPlanFrequency" lay-filter="tcPlanFrequency" lay-verify="required" required
                                id="frequency">
                                <option value=""></option>
                                <option value="H">每小时</option>
                                <option value="D">每日</option>
                                <option value="W">每周</option>
                                <option value="M">每月</option>
                            </select>
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>计划频率日期:
                        </span>
                        <span class="layui-input-box tcPlanDay">
                            <input type="text" name="tcPlanDay" id="tcPlanDay" required lay-verify="checkPlanDay"
                            id="tcPlanDate" placeholder="" autocomplete="off" class="layui-input">
                        </span>
                    </div>
                </li>
                <li class="layui-col-md3 layui-col-sm3">
                    <div class="layui-input-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>保养时间:
                        </span>
                        <span class="layui-input-box">
                            <input type="text" name="tcPlanTime" id="tcPlanTime" required lay-verify="required"
                                id="tcPlanTime" placeholder="" autocomplete="off" class="layui-input ">
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner">
                            <span style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>执行时长:
                        </span>
                        <span class="layui-input-box">
                            <select name="hour" id="" lay-filter="Houer" lay-verify="required|toPlanDuration">
                                <option value=""></option>
                                <option value="00">00小时</option>
                                <option value="01">01小时</option>
                                <option value="02">02小时</option>
                                <option value="03">03小时</option>
                                <option value="04">04小时</option>
                                <option value="05">05小时</option>
                                <option value="06">06小时</option>
                                <option value="07">07小时</option>
                                <option value="08">08小时</option>
                                <option value="09">09小时</option>
                                <option value="10">10小时</option>
                                <option value="11">11小时</option>
                                <option value="12">12小时</option>
                            </select>
                            <select name="minute" id="" lay-filter="MainTime">
                                <option value=""></option>
                                <option value="00">00分</option>
                                <option value="30">30分</option>
                            </select>
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner" style="padding-left: 8px;">
                            上次保养时间:
                        </span>
                        <span class="layui-input-box">
                        </span>
                    </div>
                    <div class="layui-input-block">
                        <span class="inner" style="padding-left: 8px;">
                            下次保养时间:
                        </span>
                        <span class="layui-input-box">
                        </span>
                    </div>
                </li>
                <li class="layui-col-md3 layui-col-sm3">
                    <div class="layui-radio-box layui-input-block">
                        <label style="padding-left: 8px;">是否自动生成工单:</label>
                        <div class="layui-input-box">
                            <input type="radio" name="tcPlanIsAuto" value="1" title="是" class="layui-radio" checked="">
                            <input type="radio" name="tcPlanIsAuto" value="0" title="否" class="layui-radio">
                        </div>
                    </div>
                    <div class="layui-input-block layui-textarea-block">
                        <span class="inner" style="padding-left: 8px;">
                            保养说明:
                        </span>
                        <span class="layui-input-box">
                            <textarea class="layui-textarea" name="tcPlanDsc" lay-verify=""></textarea>
                        </span>
                    </div>
                    <div class="layui-input-block layui-textarea-block">
                        <span class="inner">
                            <span
                                style="font-size: 18px;color: red;position: relative;display: inline-block;line-height: 20px;vertical-align: middle;top:3px;">*</span>位置范围:
                        </span>
                        <span class="layui-input-box">
                            <textarea class="layui-textarea" name="tcPlanArea" required
                                lay-verify="required"></textarea>
                        </span>
                    </div>
                </li>
            </ul>
        </div>
        <div class="layui-fluid">
            <div class="layui-title">
                <span class="layui-title-inner">保养设备基本信息填写</span>
            </div>
            <div class="btn-box layui-btn-containner">
                <button type="button" class="btn-one layui-btn layui-btn-radius layui-btn-primary">
                    <span class="add-icon"></span>
                    <span>添加保养设备</span>
                </button>
                <button type="button" class="btn-two layui-btn layui-btn-radius layui-btn-primary"> <span
                        class="add-icon"></span>
                    <span>添加保养项目</span>
                </button>
                <button type="button" class="btn-three layui-btn layui-btn-radius layui-btn-primary" id="deleteBaseInfo" style="display: flex;vertical-align: middle;line-height: 20px;">
                    <i class="layui-icon layui-icon-delete" style="font-size: 15px; color: #FFF;line-height: 20px;position: relative;
                    top: -1px;"></i>
                    <span>删除保养项目</span>
                  </button>
            </div>
            <table class="layui-table" lay-size="sm" id="baseTable">
                <thead>
                    <tr>
                        <th rowspan="2"></th>
                        <th rowspan="2">设备编号</th>
                        <th rowspan="2">设备名称</th>
                        <th rowspan="2">设备类型</th>
                        <th rowspan="2">供应商</th>
                        <th rowspan="2">设备系列</th>
                        <th rowspan="2">设备型号</th>
                        <th colspan="6">保养项目</th>
                    </tr>
                    <tr>
                        <th width="10%">项目名称</th>
                        <th width="10%">保养部位</th>
                        <th width="10%">保养说明</th>
                        <th width="10%">相关文档</th>
                        <th width="10%">操作</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <footer class="footer layui-btn-containner">
                <button type="button" class="footer-btn confirm-btn layui-btn layui-btn-radius layui-btn-primary layui-bg-red"
                    lay-submit lay-filter="save">提交</button>
                    <button type="button" class="footer-btn submit-btn layui-btn layui-btn-radius layui-btn-primary layui-bg-blue">
                        保存
                      </button>
                <button type="button"
                    class="footer-btn cancel-btn layui-btn layui-btn-radius layui-btn-primary">取消</button>
            </footer>
        </div>
    </form>
</div>


<!-- 保养设备选择 -->
<script type="text/html" id="addDeviceTpl">
    <style scoped>
        .leon-style-alert .layui-input-block,.leon-style-alert .con2 input{
        width:50%
      }
      .leon-style-alert .con2{
        padding: 0 20px;
      }
      .leon-style-alert .con2 input{
        width: 100%;
      }
      .leon-style-alert .query{
        display: block;
      }
      .leon-style-alert .layui-form-item{
        clear: none;
        width: 30%;
      }
    </style>
    <div class="leon-style-alert">
        <div class="layui-alert-box">
            <div class="layui-alert-title">
                <span class="layui-title-inner">保养设备选择</span>
                <span class="layui-title-screen">
                    <div class="screen-btn">
                      <form class="layui-form" action="">
                        <input type="search" name="keyWord" class="search-blank-inner searchInput" placeholder="搜索" autocomplete="off"/>
                        <button type="button" lay-submit lay-filter="queryTableDeviceHeader" class="search-blank-icon" ></button>
                      </form>
                    </div>
                </span>
            </div>
            <div class="layui-content">
                <div class="con1 toggle-btn">
                    <span class="screen">
                        <i class="query-icon  layui-icon"></i>
                        <span class="query-inner">查询条件</span>
                    </span>
                    <i class="icon layui-icon layui-icon-down"></i>
                </div>
                <div class="con2 toggle-content">
                    <form  class="layui-form">
                        <div class="layui-form-item layui-col-sm3 layui-col-md3">
                        <label class="layui-form-label">设备编号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="fia01" autocomplete="off" class="layui-input " />
                        </div>
                        </div>
                        <div class="layui-form-item layui-col-sm3 layui-col-md3">
                        <label class="layui-form-label">设备名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="fia02" autocomplete="off" class="layui-input " />
                        </div>
                        </div>
                        <div class="layui-form-item layui-col-sm3 layui-col-md3">
                        <label class="layui-form-label">供应商：</label>
                        <div class="layui-input-block">
                            <input type="text" name="fia09" autocomplete="off" class="layui-input " />
                        </div>
                        </div>
                        <div class="layui-form-item layui-col-sm6 layui-col-md6">
                        <label class="layui-form-label">是否启用：</label>
                        <div class="layui-input-block">
                            <select name="tcDevIsDisable" autocomplete="off">
                            <option value=""></option>
                            <option value="0">启用</option>
                            <option value="1">停用</option>
                            </select> 
                        </div>
                        </div>
                        <div class="layui-form-item layui-col-sm6 layui-col-md6">
                        <label class="layui-form-label">设备状态：</label>
                        <div class="layui-input-block">
                            <select name="fiaacti" autocomplete="off">
                            <option value=""></option>
                            <option value="0">一般</option>
                            <option value="1">良好</option>
                            <option value="2">不稳定</option>
                            <option value="3">折旧中</option>
                            <option value="4">外送</option>
                            <option value="5">折毕</option>
                            <option value="6">出售</option>
                            <option value="7">报废</option>
                            <option value="8">折毕再提</option>
                            <option value="9">改良</option>
                            <option value="A">重估</option>
                            </select> 
                        </div>
                        </div>
                        <button type="button" lay-submit lay-filter="queryTableDevice"
                        class="query layui-btn layui-btn-radius layui-btn-primary">
                        <span class="search-icon"></span>
                        <span class="btn-inner">查询</span>
                        </button>
                    </form>
                </div>
                <table class="layui-table" id="table-device-alert"></table>
            </div>
            <div class="footer layui-btn-containner">
                <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">添加</button>
                <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="addProjectTpl">
<div class="leon-style-alert">
    <div class="layui-alert-box">
        <div class="layui-alert-title">
            <span class="layui-title-inner">保养项目选择</span>
            <span class="layui-title-screen">
                <div class="screen-btn">
                    <form action="" class="layui-form">
                    <input type="search" name="keyWord" class="search-blank-inner searchInput" placeholder="搜索" autocomplete="off"/>
                    <button type="button" lay-submit lay-filter="queryTableProjectHeader" class="search-blank-icon"></button>
                    </form>
                </div>
            </span>
        </div>
        <div class="layui-content">
            <div class="con1 toggle-btn">
                <span class="screen">
                    <i class="query-icon  layui-icon"></i>
                    <span class="query-inner">查询条件</span>
                </span>
                <i class="icon layui-icon layui-icon-down"></i>
            </div>
            <div class="con2 toggle-content">
                <form action="" class="layui-form">
                    <label for="">项目名称:</label>
                    <input type="text" name="tcMaintName" />
                    <label for="">保养部位:</label>
                    <input type="text" name="tcMaintPart" />
                    <label for="">相关文档:</label>
                    <input type="text" name="tcDocName" />
                    <button type="button" lay-submit lay-filter="queryTableProject" class="query layui-btn layui-btn-radius layui-btn-primary">
                        <span class="search-icon"></span>
                        <span class="btn-inner">查询</span>
                    </button>
                </form>
            </div>
            <table class="layui-table" id="table-project-alert"></table>
        </div>
        <div class="footer layui-btn-containner">
            <button class="btn1 layui-btn layui-btn-radius layui-btn-primary">添加</button>
            <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
        </div>
    </div>
</div>
</script>

<script>
    ! function () {
        //无需再执行layui.use()方法加载模块，直接使用即可
        var $ = layui.$
        layui.use(['form', 'table', 'api', 'utill', 'laydate', 'view','admin'], function () { //此段代码必不可少
            var table = layui.table,
                setter = layui.setter,
                laytpl = layui.laytpl,
                api = layui.api,
                utill = layui.utill,
                form = layui.form,
                element = layui.element,
                laypage = layui.laypage,
                constants = layui.constants,
                admin = layui.admin,
                view = layui.view,
                laydate = layui.laydate;
            $('[data-jump="maintain/balance"]').addClass('layui-this').attr('color', '#FFF');
            form.render();
            utill.fuzzmatch('#gen02');
            var startTime = laydate.render({
                elem: '#startTime'
                ,type: 'datetime' //时间格式：yyyy/MM/dd HH:mm:ss
                ,done: function(value, date, endDate) {
                    endTime.config.min='1900-1-1';
                        startTime.config.max=endTime.config.max;
                    endTime.config.min = {
                        year: date.year,
                        month: date.month - 1,//重点！！！
                        date: date.date,
                        hours:date.hours, 
                        minutes:date.minutes, 
                        seconds:date.seconds
                    }
                    var stime = new Date(Date.parse(value.replace("-", "/")));            
                    var etime = new Date(Date.parse($("#endTime").val().replace("-", "/")));   
                    if(stime>etime){ 
                        $("#endTime").val(value);
                    }
                }
            });
            var endTime = laydate.render({
                elem: '#endTime'
                ,type: 'datetime'
                ,min: $("#startTime").val(),
                done: function(value, date, endDate) {
                    endTime.config.min='1900-1-1';
                    startTime.config.max=endTime.config.max;
                }
            });
            laydate.render({
                elem: '#tcPlanTime'
                , type: 'time'
                , format: 'HH:mm'
            });
            laydate.render({
                elem: '#tcPlanDuration'
                , type: 'time'
                , format: 'H.m'
                , max: '12:59:00'
                , btns: ['clear', 'confirm']
            });

            var status = {
                deviceIndexArr: [],
                planDetails: [],
                tcPlanFrequency: ''
            }
            var verifys = {
                checkPlanDay: function (value, item) {
                    var field = $(item).val();
                    switch (status.tcPlanFrequency) {
                        case "W":
                            if (field.length == 0 || +field > 7) {
                                return '<strong style="color: red">计划频率</strong>每周为必填项，且不能超过7';
                            }
                            break;
                        case "M":
                            if (field.length == 0 || +field > 28) {
                                return '<strong style="color: red">计划频率</strong>每月为必填项，且不能超过28';
                            }
                            break;
                        case "D":
                            if (field.length > 0) {
                                $("#tcPlanDay").val("");
                                return '<strong style="color: red">计划频率</strong>每日无需填写';
                            }
                            break;
                        case "H":
                            if (field.length > 0) {
                                $("#tcPlanDay").val("");
                                return '<strong style="color: red">计划频率</strong>每小时无需填写';
                            }
                            break;
                    }
                },
                toPlanDuration: function (value) {
                    if (1 > +value > 24) {
                        return '<strong style="color: red">执行时长</strong>必须是1至24之间';
                    }
                }

            }
            //自定义验证规则
            form.verify(verifys);
            form.on('select(tcPlanFrequency)', function (data) {
                status.tcPlanFrequency = data.value;
            })
            form.on('radio(checkArr)', function (data) {
                status.deviceIndexArr = [];
                status.deviceIndexArr.push($(data.elem).parents('tr').index());
            })
            var alertEvent = {
                addDevice: function (layero, index) {
                    form.render();
                    table.render($.extend({}, utill.tableOpts(), {
                        elem: '#table-device-alert',
                        id: "#table-device-alert",
                        height: 300,
                        toolbar: '',
                        url: api.host + api.xjjh.selectByFia01,
                        where: {
                            fia01: "",
                            fia02: "",
                            fia09: "",
                            keyWord: "",
                        },
                        cols: [[
                            { fixed: 'left', type: 'checkbox' },
                            { field: 'fia01', title: '设备编号' },
                            { field: 'fia02', title: '设备名称' },
                            { field: 'fic02', title: '设备类型' },
                            { field: 'pmc081', title: '供应商' },
                            { field: 'tcSeriesName', title: '设备系列' },
                            { field: 'fii02', title: '设备型号' }
                        ]],


                    }));
                    form.on('submit(queryTableDevice)', function (data) {
                        var allData = data.field;
                        table.reload('#table-device-alert', {
                            where: allData,
                        });
                        return false;
                    })
                    form.on('submit(queryTableDeviceHeader)', function (data) {
                        var allData = data.field;
                        table.reload('#table-device-alert', {
                            where: allData,
                        });
                        return false;
                    })
                    utill.keyup('.searchInput', '.search-blank-icon');
                    $('body').off('click', '.footer').on('click', '.footer', function (e) {
                        var $target = $(e.target);
                        if ($target.hasClass('btn1')) {
                            var checkedArr = table.checkStatus('#table-device-alert').data;
                            // 选中去重
                            if (status.planDetails.length > 0) {
                                for (var i = 0; i < status.planDetails.length; i++) {
                                    for (var j = 0; j < checkedArr.length; j++) {
                                        if (checkedArr[j].tcDevId == status.planDetails[i].tcDetailDevid) {
                                            checkedArr.splice(j, 1)
                                            j = j - 1;
                                        }
                                    }
                                }
                            }
                            checkedArr.forEach(function (item, index) {
                                var TPL = `<tr>
                                    <td><input type="radio" name="project" lay-filter="checkArr" lay-skin="primary" title=""></td>
                                    <td>${item.fia01 || ''}</td>
                                    <td>${item.fia02 || ''}</td>
                                    <td>${item.fic02 || ''}</td>
                                    <td>${item.pmc081 || ''}</td>
                                    <td>${item.tcSeriesName || ''}</td>
                                    <td>${item.fii02 || ''}</td>
                                    <td colspan="6" class="subTd">
                                        <table class="subTable">
                                        </table>
                                    </td>
                                </tr>`;
                                $('#baseTable').find('> tbody').append(TPL);
                                status.planDetails.push({
                                    planProjects: [],
                                    tcDetailDevid: item.tcDevId
                                })
                            })
                            form.render();

                        } else if ($target.hasClass('btn2')) {
                        }
                        layer.closeAll()
                    });
                },
                addProject: function (layero, index) {
                    form.render();
                    table.render($.extend({}, utill.tableOpts(), {
                        elem: '#table-project-alert',
                        id: "#table-project-alert",
                        height: 300,
                        toolbar: '',
                        cols: [[
                            { fixed: 'left', type: 'checkbox' },
                            { field: 'tcMaintName', title: '项目名称' },
                            { field: 'tcMaintPart', title: '保养部位' },
                            { field: 'tcMaintDsc', title: '保养说明' },
                            { field: 'tcDocName', title: '相关文档' },
                        ]],
                        url: api.host + api.xjjh.selectAllMaintenanceList,
                        where: {
                            tcMaintName: "",
                            tcMaintPart: "",
                            keyWord: ""
                        }
                    }));
                    form.on('submit(queryTableProjectHeader)', function (data) {
                        var allData = data.field;
                        table.reload('#table-project-alert', {
                            where: allData,
                        });
                        return false;
                    })
                    form.on('submit(queryTableProject)', function (data) {
                        var allData = data.field;
                        table.reload('#table-project-alert', {
                            where: allData,
                        });
                        return false;
                    })
                    utill.keyup('.searchInput', '.search-blank-icon');
                    $('body').off('click', '.footer').on('click', '.footer', function (e) {
                        var $target = $(e.target);
                        if ($target.hasClass('btn1')) {
                            var checkedArr = table.checkStatus('#table-project-alert').data;

                            // 选中去重
                            if (status.planDetails.length > 0) {
                                var planProjects = status.planDetails[status.deviceIndexArr[0]].planProjects;
                                for (var i = 0; i < planProjects.length; i++) {
                                    for (var j = 0; j < checkedArr.length; j++) {
                                        if (checkedArr[j].tcMaintId == planProjects[i].tcProjProjid) {
                                            checkedArr.splice(j, 1)
                                            j = j - 1;
                                        }
                                    }
                                }
                            }
                            checkedArr.forEach(function (item, index) {
                                var TPL = `<tr class="subTr editTr">
                                    <td>${item.tcMaintName || ''}</td>
                                    <td>${item.tcMaintPart || ''}</td>
                                    <td>${item.tcMaintDsc || ''}</td>
                                    <td>${item.tcDocName || ''}</td>
                                    <td><span class="deleteProject delect icon"></span></td>
                                </tr>`;
                                $('#baseTable').find('> tbody > tr').eq(status.deviceIndexArr[0]).find('> td:last-child').find('table').append(TPL);
                                status.planDetails[status.deviceIndexArr[0]].planProjects.push({
                                    tcProjProjid: item.tcMaintId
                                })
                            })
                            form.render();
                            layer.closeAll()
                        } else if ($target.hasClass('btn2')) {
                            layer.closeAll()
                        }
                    });

                },
            }
            function tab(data){
        var val;
        if($("#tcPlanDay").val() != undefined){
            val = $("#tcPlanDay").val();
        }else{
            val = '';
        }
        if(data == 'H' || data == 'D'){
            $("[name='tcPlanDay']").attr('disabled','disabled');
            $(".tcPlanDay").empty()
            }else if(data == 'W'){
            var tcPlanDayArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
            var str = `<select name="tcPlanDay" lay-filter="tcPlanDay" lay-verify="checkPlanDay" required id="tcPlanDay">`;
            tcPlanDayArr.forEach(function(elem,i){
                if(val == i+1){
                str +=  `<option value='${i+1}' selected class="layui-this">${elem}</option>`
                }else if(val == ""){
                str +=  `<option value='${i+1}'>${elem}</option>`
                }else{
                str +=  `<option value='${i+1}'>${elem}</option>`
                }
            
            })
            str += `</select>`;
            $(".tcPlanDay").html(str);
            form.render('select');
            }else if(data == 'M'){
            let frequency = $('.layui-this:selected').val()
            let el_data;
            if(val != "" && val != undefined){
                el_data = val
            }else if(frequency != undefined){
                el_data = frequency;
            }else{
                el_data = '';
            }
            $(".tcPlanDay").empty()
            var str =  `<input name="tcPlanDay" id="tcPlanDay" autocomplete="off" class="layui-input" required
                lay-verify="required" lay-filter="checkPlanDay" placeholder="请输入1至28纯数字" title="请输入1至28有效数字"  value="${el_data}"/>`;
            $(".tcPlanDay").html(str);

            }
        }
            tab($('#frequency').val());
            form.on('select(tcPlanFrequency)', function(data){
                tab(data.value);
            })
            $('body').off('click', '.deleteProject').on('click', '.deleteProject', function (e) {
                var $target = $(e.target);
                var subIndex = $target.parents('.subTr').index();
                var parentId = $target.parents('.subTable').parents('tr').index();
                $target.parents('.subTr').remove();
                status.planDetails[parentId].planProjects.splice(subIndex, 1);
            })
            $('#deleteBaseInfo').click(function () {
                status.deviceIndexArr.forEach(function (itemIndex) {
                    status.planDetails.splice(itemIndex, 1);
                    status.deviceIndexArr.pop()
                    $("#baseTable > tbody > tr").eq(itemIndex).remove();
                })
            })

            $('.btn-box').on('click', '.btn-one', function (e) {
                layer.open({
                    type: 1,
                    title: false,
                    area: ['662px', '580px'],
                    fixed: true,
                    shadeClose: true,
                    closeBtn: 0,
                    content: $('#addDeviceTpl').html(),
                    success: alertEvent.addDevice
                });
            })
            $('.btn-box').on('click', '.btn-two', function (e) {
                if (status.deviceIndexArr.length) {
                    layer.open({
                        type: 1,
                        title: false,
                        area: ['662px', '536px'],
                        fixed: true,
                        shadeClose: true,
                        closeBtn: 0,
                        content: $('#addProjectTpl').html(),
                        success: alertEvent.addProject
                    });
                } else {
                    layer.msg('请选择一项数据进行操作！');
                }
            })
            $('footer').on('click','.submit-btn',function(){
                let data = form.val("formData");
                data.tcPlanStatus1 = 1;
                if(data.tcPlanName == ''){
                    layer.open({
                    content: '请填写巡检计划名称!'
                    })
                }else{
                    admin.req({
                    url: api.host + api.xjjh.insertMPlan1,
                    type: "POST",
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    success: function(res){
                        if(res.code == 0){
                        layer.open({
                            content: res.message
                        });
                        setTimeout(function(){
                            location.hash = '/maintain/balance'
                        },1500);
                        }else{
                        layer.open({
                            content: res.message
                        });
                        }
                    }
                    })
                }
                
                })
            // 提交
            form.on('submit(save)', function (data) {
                var baseData = data.field;
                if (!status.planDetails.length) {
                    layer.msg('请添加巡检设备基本信息')
                    return false;
                }
                  var opts = {
                    planDetails: status.planDetails
                }
                opts.tcPlanStatus1 = 1
                opts = $.extend({}, opts, baseData);
                opts['tcPlanGen01'] = $('#gen02').data('id')
                view.req({
                    url: api.host + api.xjjh.insertMPlan,
                    type: 'POST',
                    data: JSON.stringify(opts),
                    contentType: 'application/json',
                }).done(function (res) {
                    if (res.code == "0") {
                        setTimeout(function () {
                            $('.cancel-btn').click();
                        }, 1500)
                    }
                    layer.msg(res.message)
                })
                return false;
            })
            // 关闭
            $('.cancel-btn').attr('lay-href', 'maintain/balance');
            utill.dropdownEvent();
        })

        $('[data-jump="maintain/balance"]').addClass('layui-this');


    }();
</script>
<style scoped>
.layui-input-box{
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.layui-form-radio{
    margin: 0;
    margin-right: 10px;
}
.btn-three{
    flex-flow: row nowrap;
    width: auto;
    height: 20px;
    line-height: 20px;
    font-size: 9px;
    color: #fff;
    padding: 0 5px;
    border: 0;
    background-color:#FF4C4C;
  }
    .leon-style .layui-input-block {
        display: flex;
        align-items: center;
        justify-content: center;
    }
 .leon-style .layui-textarea-block {
        min-height: 35px;
    }

    .leon-style .layui-textarea {
        min-height: auto;
        line-height: 1;
        min-height: 40px;
        resize: vertical;
    }


    .leon-style .layui-radio-box {
        height: 14px;
    }

    .leon-style .layui-radio-box .layui-form-radio {
        margin: 0;
        margin-right: 10px;
    }

    .leon-style .box {
        overflow: inherit;
    }

    .leon-style .layui-form-radio>i {
        font-size: 15px;
    }

    .leon-style .layui-form-radio>div {
        font-size: 12px;
    }

    .leon-style .layui-table-tool {
        display: none;
    }

    .leon-style .layui-table[lay-size=sm] th,
    .leon-style .layui-table-cell {
        padding: 0;
    }

    #baseTable td table {
        width: 100%;
    }

    /*不显示秒*/
    #layui-laydate4 .layui-laydate-content>.layui-laydate-list {
        padding-bottom: 0px;
        overflow: hidden;
    }

    #layui-laydate4 .layui-laydate-content>.layui-laydate-list>li {
        width: 50%
    }

    #layui-laydate4 .merge-box .scrollbox .merge-list {
        padding-bottom: 5px;
    }

    .layui-table[lay-size=sm] .subTd {
        padding: 0;
    }

    .subTable .subTr td {
        width: 10%;
        white-space: pre-wrap;
    }

    .subTable .editTr.editTr td {
        width: 10%;
        white-space: pre-wrap;
    }
</style>